using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Drawing;

namespace DC2010.Tools
{
    /// <summary>
    /// ImageListBox item class
    /// </summary>
    [Serializable()]
    [ToolboxItem(false)]
    [DesignTimeVisible(false)]
    [TypeConverter(typeof(ImageListBoxItemConverter))]
    [DefaultProperty("Text")]
    public class ImageListBoxItem : ICloneable, ISerializable
    {
        private string text;
        public Image image = null;

         /// <summary>
        /// The image list for this item. Used by UI editor
        /// </summary>
        [Browsable(true)]
        public Image Image
        {
            get { return this.image; }
            set { this.image = value; }
        }

        /// <summary>
        /// The item's text
        /// </summary>
        [Localizable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string Text
        {
            get { return this.text; }
            set { this.text = value; }
        }

        private object tag;
        public object Tag
        {
            get { return this.tag; }
            set { tag = value; }
        }

        private object type;
        public object Type
        {
            get { return this.type; }
            set { type = value; }
        }

        private Color _color;
        public Color _Color
        {
            get { return this._color; }
            set { _color = value; }
        }
        
        /// <summary>
        /// Item constructors
        /// </summary>
        public ImageListBoxItem(string Text, Image Image, object Tag)
        {
            this.text = Text;
            this.Image = Image;
            this.Tag = Tag;
            this._Color = Color.Black;
        }

        public ImageListBoxItem(string Text, Image Image, object Tag, Color TextColor)
        {
            this.text = Text;
            this.Image = Image;
            this.Tag = Tag;
            this._Color = TextColor;
        }


        public ImageListBoxItem(string Text, Image Image) : this(Text, Image, null)
        {
            this.text = Text;
            this.Image = Image;
            this._Color = Color.Black;
        }

        public ImageListBoxItem(string Text) : this(Text, null)
        {
        }

        public ImageListBoxItem() : this("")
        {
        }

        #region ICloneable implemented members...

        public object Clone() 
        {
            return new ImageListBoxItem(this.text, this.Image);
        }

        #endregion

        #region ISerializable implemented members...

        public ImageListBoxItem(SerializationInfo info, StreamingContext context) 
        {
            this.text = (string)info.GetValue("Text", typeof(string));
            this.image = (Image)info.GetValue("Image", typeof(Image));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Text", this.text);
            info.AddValue("Image", this.image);
        }

        #endregion

        /// <summary>
        /// Converts the item to string representation. Needed for property editor
        /// </summary>
        /// <returns>String representation of the item</returns>
        public override string ToString()
        {
            return "Item: {" + this.text + "}";
        }
    }
}
